home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Kant Generator Pro 1.0.1 / source / Shell ƒ / other MSG window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  6.4 KB  |  262 lines  |  [TEXT/MMCC]

  1. #include "other MSG window.h"
  2. #include "environment.h"
  3. #include "menus.h"
  4. #include "util.h"
  5. #include "file utilities.h"
  6. #include "main.h"
  7. #include "text twiddling.h"
  8. #include "generic window handlers.h"
  9. #include "graphics.h"
  10. #include "window layer.h"
  11. #include "program globals.h"
  12. #include <Folders.h>
  13.  
  14. #define kGrowBoxSize        15
  15. #define PROGRAMS_LIST_NAME    "\pMSG programs list"
  16. #define kListResourceID        151
  17. #define LIST_CREATOR        'ttxt'
  18. #define LIST_TYPE            'ttro'
  19.  
  20. static    Boolean GetListFromDisk(void);
  21. static    Boolean SetupNewListFile(short fileID);
  22. static    Boolean GetListFromResource(void);
  23. static    unsigned long GetModificationDate(FSSpec *theFS);
  24. static    void PutProductListIntoTE(WindowPtr theWindow);
  25.  
  26. static    short            gOldForegroundTime;        /* stored foreground wait time */
  27. static    Boolean            gIsActive=FALSE;
  28. static    Handle            gTheList=0L;
  29. static    Boolean            gSetupDone=FALSE;
  30.  
  31. void SetupTheOtherMSGWindow(WindowPtr theWindow)
  32. {
  33.     unsigned char    *titleStr="\pOther MSG products";
  34.     Point            topLeft;
  35.     
  36.     SetWindowHeight(theWindow,
  37.         qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-LMGetMBarHeight()-28);
  38.     SetWindowWidth(theWindow, qd.screenBits.bounds.right-qd.screenBits.bounds.left-70);
  39.     SetWindowType(theWindow, zoomDocProc);
  40.     topLeft.v=qd.screenBits.bounds.top+LMGetMBarHeight()+20;
  41.     topLeft.h=qd.screenBits.bounds.left+10;
  42.     SetWindowTopLeft(theWindow, topLeft);
  43.     SetWindowHasCloseBox(theWindow, TRUE);
  44.     SetWindowMaxDepth(theWindow, 1);
  45.     SetWindowDepth(theWindow, 1);
  46.     SetWindowAutoCenter(theWindow, FALSE);
  47.     SetWindowTitle(theWindow, titleStr);
  48.     SetWindowIsFloat(theWindow, FALSE);
  49.     
  50.     if (gSetupDone)
  51.         return;
  52.     
  53.     if (!GetListFromDisk())
  54.         GetListFromResource();
  55. }
  56.  
  57. void OpenTheOtherMSGWindow(WindowPtr theWindow)
  58. {
  59.     TEHandle        hTE;
  60.     FontInfo        theFontInfo;
  61.     Rect            vScrollBarRect, hScrollBarRect;
  62.     Rect            destRect, viewRect;
  63.     
  64.     hTE=GetWindowTE(theWindow);
  65.     if (hTE==0L)
  66.     {
  67.         SetRect(&vScrollBarRect, GetWindowWidth(theWindow)-kGrowBoxSize, -1,
  68.             GetWindowWidth(theWindow)+1, GetWindowHeight(theWindow)+1-kGrowBoxSize);
  69.         SetRect(&hScrollBarRect, -1, GetWindowHeight(theWindow)-kGrowBoxSize,
  70.             GetWindowWidth(theWindow)-kGrowBoxSize+1, GetWindowHeight(theWindow)+1);
  71.         SetWindowVScrollBar(theWindow,
  72.             NewControl(theWindow, &vScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  73.         SetWindowHScrollBar(theWindow,
  74.             NewControl(theWindow, &hScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  75.         
  76.         GetTERect(theWindow, &destRect, TRUE);
  77.         viewRect=destRect;
  78.         hTE=TENew(&destRect, &viewRect);
  79.         SetWindowTE(theWindow, hTE);
  80.         TextFont((**hTE).txFont=36);
  81.         TextSize((**hTE).txSize=12);
  82.         TextFace((**hTE).txFace=0);
  83.         GetFontInfo(&theFontInfo);
  84.         (**hTE).fontAscent=theFontInfo.ascent;
  85.         (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
  86.         AdjustViewRect(hTE);
  87.         TEAutoView(TRUE, hTE);
  88.         TESetClickLoop((ProcPtr)MyClikLoop, hTE);
  89.         PutProductListIntoTE(theWindow);
  90.     }
  91.     
  92.     gIsActive=TRUE;
  93.     AdjustVScrollBar(GetWindowVScrollBar(theWindow), hTE);
  94.     AdjustMenus();
  95. }
  96.  
  97. void DisposeTheOtherMSGWindow(WindowPtr theWindow)
  98. {
  99.     TEHandle        hTE;
  100.     
  101.     hTE=GetWindowTE(theWindow);
  102.     if (hTE!=0L)
  103.     {
  104.         TEDispose(hTE);
  105.         SetWindowTE(theWindow, 0L);
  106.     }
  107. }
  108.  
  109. void ActivateTheOtherMSGWindow(WindowPtr theWindow)
  110. {
  111.     gOldForegroundTime=gForegroundWaitTime;
  112.     gForegroundWaitTime=0;
  113.     gIsActive=TRUE;
  114. }
  115.  
  116. void DeactivateTheOtherMSGWindow(WindowPtr theWindow)
  117. {
  118.     gForegroundWaitTime=gOldForegroundTime;
  119.     gCustomCursor=FALSE;
  120. }
  121.  
  122. void CopybitsTheOtherMSGWindow(WindowPtr theWindow, WindowPtr offscreenWindowPtr)
  123. {
  124.     GenericCopybits(theWindow, offscreenWindowPtr, gIsActive);
  125. }
  126.  
  127. /* ---------------------------------------------------- */
  128. /* the rest of these are internal to other MSG window.h */
  129.  
  130. static    void PutProductListIntoTE(WindowPtr theWindow)
  131. {
  132.     long            listEOF;
  133.     
  134.     if (gTheList==0L)
  135.         return;
  136.     
  137.     listEOF=GetHandleSize(gTheList);
  138.     HLock(gTheList);
  139.     SetTheText(theWindow, *gTheList, listEOF);
  140.     HUnlock(gTheList);
  141.     TESetSelect(0, 0, GetWindowTE(theWindow));
  142. }
  143.  
  144. static    Boolean GetListFromDisk(void)
  145. {
  146.     Boolean            isNewFile;
  147.     unsigned char    *name=PROGRAMS_LIST_NAME;
  148.     OSErr            isHuman;
  149.     short            vRefNum;
  150.     long            dirID;
  151.     FSSpec            listFileFS, progFS;
  152.     short            listFile;
  153.     long            listEOF;
  154.     unsigned long    diskListModDate, ourListModDate;
  155.     
  156.     isNewFile=FALSE;
  157.     /* find vRefNum and dirID of preferences folder, creating it if necessary */
  158.     isHuman=FindFolder(kOnSystemDisk, 'pref', kCreateFolder, &vRefNum, &dirID);
  159.     
  160.     if (isHuman!=noErr)        /* screwed up already?!? */
  161.         return FALSE;
  162.     
  163.     isHuman=FSMakeFSSpec(vRefNum, dirID, name, &listFileFS);    /* make FSSpec out of it */
  164.     if (isHuman!=noErr)
  165.     {
  166.         if (isHuman==fnfErr)    /* FSSpec is valid, but list file does not exist */
  167.         {
  168.             isHuman=FSpCreate(&listFileFS, LIST_CREATOR, LIST_TYPE, 0);    /* so create it */
  169.             if (isHuman!=noErr)                                        /* or not */
  170.                 return FALSE;
  171.             isNewFile=TRUE;        /* signal that list file is new */
  172.         }
  173.         else return FALSE;
  174.     }
  175.     isHuman=FSpOpenDF(&listFileFS, fsRdWrPerm, &listFile);    /* open list file */
  176.     if (isHuman!=noErr)
  177.         return FALSE;
  178.     
  179.     diskListModDate=GetModificationDate(&listFileFS);
  180.     GetApplicationFSSpec(&progFS);
  181.     ourListModDate=GetModificationDate(&progFS);
  182.     if (diskListModDate<ourListModDate)
  183.         isNewFile=TRUE;
  184.     
  185.     if (isNewFile)
  186.     {
  187.         if (!SetupNewListFile(listFile))
  188.         {
  189.             FSClose(listFile);
  190.             FSpDelete(&listFileFS);
  191.             return FALSE;
  192.         }
  193.         SetModificationDate(&listFileFS, ourListModDate);
  194.     }
  195.     else
  196.     {
  197.         GetEOF(listFile, &listEOF);
  198.         gTheList=NewHandle(listEOF);
  199.         if (gTheList==0L)
  200.         {
  201.             FSClose(listFile);
  202.             FSpDelete(&listFileFS);
  203.             return FALSE;
  204.         }
  205.         HLock(gTheList);
  206.         SetFPos(listFile, 1, 0L);
  207.         if (FSRead(listFile, &listEOF, *gTheList)!=noErr)
  208.         {
  209.             FSClose(listFile);
  210.             FSpDelete(&listFileFS);
  211.             DisposeHandle(gTheList);
  212.             gTheList=0L;
  213.             return FALSE;
  214.         }
  215.         HUnlock(gTheList);
  216.     }
  217.     
  218.     FSClose(listFile);
  219. //    FlushVol(dirID, vRefNum);
  220.     
  221.     return TRUE;
  222. }
  223.  
  224. static    Boolean SetupNewListFile(short fileID)
  225. {
  226.     long            listEOF;
  227.     
  228.     if (!GetListFromResource())
  229.         return FALSE;
  230.     
  231.     listEOF=GetHandleSize(gTheList);
  232.     if (SetEOF(fileID, listEOF)!=noErr)
  233.         return FALSE;
  234.     
  235.     SetFPos(fileID, 1, 0L);
  236.     HLock(gTheList);
  237.     if (FSWrite(fileID, &listEOF, *gTheList)!=noErr)
  238.         return FALSE;
  239.     HUnlock(gTheList);
  240.     
  241.     return TRUE;
  242. }
  243.  
  244. static    Boolean GetListFromResource(void)
  245. {
  246.     gTheList=(Handle)Get1Resource('TEXT', kListResourceID);
  247.     if (gTheList==0L)
  248.         return FALSE;
  249.     if (*gTheList==0L)
  250.         LoadResource(gTheList);
  251.     if (*gTheList==0L)
  252.     {
  253.         DisposeHandle(gTheList);
  254.         gTheList=0L;
  255.         return FALSE;
  256.     }
  257.     
  258.     DetachResource(gTheList);
  259.     
  260.     return TRUE;
  261. }
  262.